﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_dokument_maarus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedDokumentMaarus))]
    public class DetailandmedDokumentMaarusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedDokumentMaarus clazz;
        
        public DetailandmedDokumentMaarusSerializer(IDetailandmedDokumentMaarus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.MaaruseId!=null) {
                Writer.WriteStartElement("maaruse_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.MaaruseId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseNr!=null) {
                Writer.WriteStartElement("maaruse_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseKpv!=null) {
                Writer.WriteStartElement("maaruse_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.MaaruseKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseLiik!=null) {
                Writer.WriteStartElement("maaruse_liik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseLiikTekstina!=null) {
                Writer.WriteStartElement("maaruse_liik_tekstina");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseLiikTekstina))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseOlek!=null) {
                Writer.WriteStartElement("maaruse_olek");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseOlek))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeJoustumiseKpvVoiMaaruseLisatahtaeg!=null) {
                Writer.WriteStartElement("kande_joustumise_kpv_voi_maaruse_lisatahtaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeJoustumiseKpvVoiMaaruseLisatahtaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kandeliik!=null) {
                Writer.WriteStartElement("kandeliik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kandeliik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeliikTekstina!=null) {
                Writer.WriteStartElement("kandeliik_tekstina");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeliikTekstina))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="maaruse_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_id");
                }
                clazz.MaaruseId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("maaruse_id")).Value;
            }
            if (Reader.LocalName=="maaruse_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_nr");
                }
                clazz.MaaruseNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_nr")).Value;
            }
            if (Reader.LocalName=="maaruse_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_kpv");
                }
                clazz.MaaruseKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("maaruse_kpv")).Value;
            }
            if (Reader.LocalName=="maaruse_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_liik");
                }
                clazz.MaaruseLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_liik")).Value;
            }
            if (Reader.LocalName=="maaruse_liik_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_liik_tekstina");
                }
                clazz.MaaruseLiikTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_liik_tekstina")).Value;
            }
            if (Reader.LocalName=="maaruse_olek") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>maaruse_olek");
                }
                clazz.MaaruseOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_olek")).Value;
            }
            if (Reader.LocalName=="kande_joustumise_kpv_voi_maaruse_lisatahtaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>kande_joustumise_kpv_voi_maaruse_lisatahtaeg");
                }
                clazz.KandeJoustumiseKpvVoiMaaruseLisatahtaeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_joustumise_kpv_voi_maaruse_lisatahtaeg")).Value;
            }
            if (Reader.LocalName=="kandeliik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>kandeliik");
                }
                clazz.Kandeliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik")).Value;
            }
            if (Reader.LocalName=="kandeliik_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokument_maarus>kandeliik_tekstina");
                }
                clazz.KandeliikTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandeliik_tekstina")).Value;
            }
        }
    }
}
